/**
  ******************************************************************************
  * @file    lwipopts.h
  * @author  MCD Application Team
  * @version V1.1.0
  * @date    31-July-2013
  * @brief   lwIP Options Configuration.
  *          This file is based on Utilities\lwip_v1.4.1\src\include\lwip\opt.h 
  *          and contains the lwIP configuration for the STM32F4x7 demonstration.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__


 /*
   ------------------------------------
   -------------- NO SYS --------------
   ------------------------------------
*/
/**
 * NO_SYS==1: Use lwIP without OS-awareness (no thread, semaphores, mutexes or
 * mboxes)
 */
#define NO_SYS                      0
/**
 * NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
 * Mainly for compatibility to old versions.
 */
#define NO_SYS_NO_TIMERS            0


/*
   ------------------------------------
   ----------- Core locking -----------
   ------------------------------------
*/
/**
 * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
 * critical regions during buffer allocation, deallocation and memory
 * allocation and deallocation.
 */
#define SYS_LIGHTWEIGHT_PROT        1


/*
   ------------------------------------
   ---------- Memory options ----------
   ------------------------------------
*/
/**
 * MEM_ALIGNMENT: should be set to the alignment of the CPU
 *    4 byte alignment -> \#define MEM_ALIGNMENT 4
 *    2 byte alignment -> \#define MEM_ALIGNMENT 2
 */
#define MEM_ALIGNMENT               4
/**
 * MEM_SIZE: the size of the heap memory. If the application will send
 * a lot of data that needs to be copied, this should be set high.
 */
#define MEM_SIZE                    (15 * 1024)
/**
 * MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable
 * amount of bytes before and after each memp element in every pool and fills
 * it with a prominent default value.
 *    MEMP_OVERFLOW_CHECK == 0 no checking
 *    MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed
 *    MEMP_OVERFLOW_CHECK >= 2 checks each element in every pool every time
 *      memp_malloc() or memp_free() is called (useful but slow!)
 */
#define MEMP_OVERFLOW_CHECK         1


/*
   ------------------------------------------------
   ---------- Internal Memory Pool Sizes ----------
   ------------------------------------------------
*/
/**
 * MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
 * sends a lot of data out of ROM (or other static memory), this
 * should be set high.
 */
#define MEMP_NUM_PBUF               32
/**
 * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
 * per active UDP "connection".
 */
#define MEMP_NUM_UDP_PCB            4
/**
 * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
 * connections.
 */
#define MEMP_NUM_TCP_PCB            4
/**
 * the number of UDP protocol control blocks. One per active RAW "connection".
 */
#define MEMP_NUM_RAW_PCB            4
/**
 * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
 * connections.
 */
#define MEMP_NUM_TCP_PCB_LISTEN     8
/**
 * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
 *  segments.
 */
#define MEMP_NUM_TCP_SEG            40
/**
 * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
 *  timeouts.
 */
#define MEMP_NUM_SYS_TIMEOUT        8
/**
 * MEMP_NUM_NETCONN: the number of struct netconns. */
#define MEMP_NUM_NETCONN            8
/**
 * PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
 */
#define PBUF_POOL_SIZE              16


/*
   ----------------------------------
   ---------- Pbuf options ----------
   ----------------------------------
*/
/**
 * PBUF_LINK_HLEN: the number of bytes that should be allocated for a
 * link level header.
 */
#define PBUF_LINK_HLEN              16
/**
 * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is
 * designed to accommodate single full size TCP frame in one pbuf, including
 * TCP_MSS, IP header, and link header.
 */
#define PBUF_POOL_BUFSIZE           LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)


/*
   ---------------------------------
   ---------- TCP options ----------
   ---------------------------------
*/
/**
 * LWIP_TCP==1: Turn on TCP.
 */
#define LWIP_TCP                    1
/**
 * TCP_TTL: Default Time-To-Live value.
 */
#define TCP_TTL                     255
/**
 * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
 * Define to 0 if your device is low on memory.
 */
#define TCP_QUEUE_OOSEQ             1
/**
 * TCP_MSS: TCP Maximum segment size.
 */
#define TCP_MSS                     (1500 - 40)	  /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
/**
 * TCP_SND_BUF: TCP sender buffer space (bytes).
 */
#define TCP_SND_BUF                 8196
/**
 * TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
 * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work.
 */
#define TCP_SND_QUEUELEN            (4 * TCP_SND_BUF / TCP_MSS)
/* TCP writable space (bytes). This must be less than or equal
   to TCP_SND_BUF. It is the amount of space which must be
   available in the tcp snd_buf for select to return writable */
#define TCP_SNDLOWAT                (TCP_SND_BUF / 2)
/**
 * TCP_SNDQUEUELOWAT: TCP writable bufs (pbuf count). This must be less
 * than TCP_SND_QUEUELEN. If the number of pbufs queued on a pcb drops below
 * this number, select returns writable (combined with TCP_SNDLOWAT).
 */
#define TCP_SNDQUEUELOWAT           (TCP_SND_QUEUELEN / 2)
/**
 * TCP_WND: The size of a TCP window.
 */
#define TCP_WND                     8196
/**
 * TCP_MAXRTX: Maximum number of retransmissions of data segments.
 */
#define TCP_MAXRTX                  12
/**
 * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
 */
#define TCP_SYNMAXRTX               4
/**
 * TCP_TMR_INTERVAL: The TCP timer interval in milliseconds.
 */
#define TCP_TMR_INTERVAL            25


/*
   ------------------------------------------------
   ---------- Network Interfaces options ----------
   ------------------------------------------------
*/
/**
 * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname field.
 */
#define LWIP_NETIF_HOSTNAME         1
/**
 * LWIP_NETIF_API==1: Support netif api (in netifapi.c)
 */
#define LWIP_NETIF_API              1


/*
   ----------------------------------
   ---------- ICMP options ----------
   ----------------------------------
*/
/**
 * LWIP_ICMP==1: Enable ICMP module inside the IP stack.
 * Be careful, disable that make your product non-compliant to RFC1122
 */
#define LWIP_ICMP                   1


/*
   ---------------------------------
   ---------- ARP options ----------
   ---------------------------------
*/
/**
 * LWIP_ARP==1: Enable ARP functionality.
 */
#define LWIP_ARP                    1
/**
 * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached.
 */
#define ARP_TABLE_SIZE              10
/**
 * ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address
 * resolution.
 */
#define ARP_QUEUEING                1


/*
   ----------------------------------
   ---------- DNS options -----------
   ----------------------------------
*/
/**
 * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS
 * transport.
 */
#define LWIP_DNS                    1
/** 
  * DNS_SERVER_ADDRESS: DNS server IP address.
  */
#ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS(ipaddr)  (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
#endif


/*
   ----------------------------------
   ---------- IGMP options ----------
   ----------------------------------
*/
/**
 * LWIP_IGMP==1: Turn on IGMP module.
 */
#define LWIP_IGMP                   1
/**
  * LWIP_RAND: Define random number generator function of your system.
  */
#ifdef LWIP_IGMP
#include <stdlib.h>
#define LWIP_RAND                   rand
#endif


/*
   ------------------------------------
   ---------- LOOPIF options ----------
   ------------------------------------
*/
/**
 * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1).
 */
#define LWIP_HAVE_LOOPIF            0


/*
   ----------------------------------
   ---------- DHCP options ----------
   ----------------------------------
*/
/**
 * LWIP_DHCP==1: Enable DHCP module.
 */
#define LWIP_DHCP                   0


/*
   ---------------------------------
   ---------- UDP options ----------
   ---------------------------------
*/
/**
 * LWIP_UDP==1: Turn on UDP.
 */
#define LWIP_UDP                    1
/**
 * UDP_TTL: Default Time-To-Live value.
 */
#define UDP_TTL                     255


/*
   ----------------------------------------
   ---------- Statistics options ----------
   ----------------------------------------
*/
/**
 * LWIP_STATS==1: Enable statistics collection in lwip_stats.
 */
#define LWIP_STATS                  0


/*
   --------------------------------------
   ---------- Checksum options ----------
   --------------------------------------
*/
/**
 * CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.
 */
#define CHECKSUM_GEN_IP             0
/**
 * CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.
 */
#define CHECKSUM_GEN_UDP            0
/**
 * CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.
 */
#define CHECKSUM_GEN_TCP            0 
/**
 * CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.
 */
#define CHECKSUM_CHECK_IP           0
/**
 * CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.
 */
#define CHECKSUM_CHECK_UDP          0
/**
 * CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.
 */
#define CHECKSUM_CHECK_TCP          0
/**
 * CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.
 */
#define CHECKSUM_GEN_ICMP           0


/*
   ----------------------------------------------
   ---------- Sequential layer options ----------
   ----------------------------------------------
*/
/**
 * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
 */
#define LWIP_NETCONN                1


/*
   ------------------------------------
   ---------- Socket options ----------
   ------------------------------------
*/
/**
  * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) 
  */
#define LWIP_SOCKET                 1
/**
  * LWIP_SOCKET_POLL==1: enable select() for sockets (uses a netconn callback to keep track of events)
  */
#define LWIP_SOCKET_SELECT          1
/**
  * LWIP_SOCKET_POLL==1: enable poll() for sockets (including struct pollfd, nfds_t, and constants)
  */
#define LWIP_SOCKET_POLL            1
/**
 * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
 * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set
 * in seconds. (does not require sockets.c, and will affect tcp.c)
 */
#define LWIP_TCP_KEEPALIVE          1


/*
   ---------------------------------
   ---------- RAW options ----------
   ---------------------------------
*/
/**
 * LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
 */
#define LWIP_RAW                    1


/*
   ---------------------------------------
   ---------- IPv6 options ---------------
   ---------------------------------------
*/
/**
 * LWIP_IPV6==1: Enable IPv6
 */
#define LWIP_IPV6                   0


/*
   ------------------------------------
   ---------- Thread options ----------
   ------------------------------------
*/
/**
 * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
 * NETCONN_UDP.
 */
#define DEFAULT_UDP_RECVMBOX_SIZE   1
/**
 * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
 * NETCONN_TCP.
 */
#define DEFAULT_TCP_RECVMBOX_SIZE   10
/**
 * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
 */
#define DEFAULT_ACCEPTMBOX_SIZE     10
/**
 * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread.
 */
#define DEFAULT_THREAD_STACKSIZE    1024
/**
 * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread.
 */
#define DEFAULT_THREAD_PRIO		    25
/**
 * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a
 * NETCONN_RAW.
 */
#define DEFAULT_RAW_RECVMBOX_SIZE   1
/**
 * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
 */
#define RECV_BUFSIZE_DEFAULT        8192

/**
 * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread.
 */
#define TCPIP_THREAD_NAME           "lwip"
/**
 * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread.
 */
#define TCPIP_THREAD_STACKSIZE      1024
/**
 * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
 * The queue size value itself is platform-dependent, but is passed to
 * sys_mbox_new() when tcpip_init is called.
 */
#define TCPIP_MBOX_SIZE             8
/**
 * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread.
 */
#define TCPIP_THREAD_PRIO           31


#endif /* __LWIPOPTS_H__ */
